import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import swal, { SweetAlertType } from 'sweetalert2';

@Component({
  selector: 'app-c-txt-tool',
  templateUrl: './c-txt-tool.component.html',
  styleUrls: ['./c-txt-tool.component.less']
})
export class CTxtToolComponent implements OnInit {
  @Output() onChange = new EventEmitter<any>();
  @Output() onChangeTxt = new EventEmitter<any>();
  @Output() onDelete = new EventEmitter<any>();
  _rightText;
  @Input() rightData;

  set rightText(value){
      this.rightData.text = value;
      this.onChangeTxt.emit(this.rightData);
  }

  get rightText(){
      return this.rightData.text;
  }

  _rightStyleX;
  @Input()
  set rightStyleX(value){
      this._rightStyleX = value;
      this.emitXYWH();
  }

  get rightStyleX(){
      return this._rightStyleX;
  }

    _rightStyleY;
    @Input()
    set rightStyleY(value){
        this._rightStyleY = value;
        this.emitXYWH();
    }

    get rightStyleY(){
        return this._rightStyleY;
    }

    _rightStyleW;
    @Input()
    set rightStyleW(value){
        this._rightStyleW = value;
        this.emitXYWH();
    }

    get rightStyleW(){
        return this._rightStyleW;
    }

    _rightStyleH;
    @Input()
    set rightStyleH(value){
        this._rightStyleH = value;
        this.emitXYWH();
    }

    get rightStyleH(){
        return this._rightStyleH;
    }



  constructor() { }

  ngOnInit() {

  }

  emitXYWH() {
      this.onChange.emit({
          x: this._rightStyleX,
          y: this._rightStyleY,
          width: this._rightStyleW,
          height: this._rightStyleH
      });
  }

  deleteComponent() {
      this.onDelete.emit();
  }

    save() {
        swal(`保存成功`, '', 'info');
    }
}
